package com.itheima;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.function.Consumer;

public class ArrayListDemo {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<String>();

        list.add("zhangsan");
        list.add(0, "list");

        String s = list.get(1);
        System.out.println(s);

        list.set(0, "wangwu");
        list.remove(1);
        list.add("zhangsan");
        list.add("lisi");
        list.add("wangwu");
        list.add("zhaoliu");
        list.add("zhaoliu");


        System.out.println(list);
        System.out.println("-----------------集合的遍历方法-------------------------------");

        //1.for循环的形式
        for (int i = 0; i < list.size(); i++) {
            String obj = list.get(i);
            System.out.println(obj);
        }
        //2.增强for循环的形式
        for (String obj : list){
            System.out.println(obj);
        }
        //3.迭代器的形式
        System.out.println("-----------------集合的遍历方法3-------------------------------");
        //获取集合的迭代器对象
        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()){
            String next = iterator.next();
            System.out.println(next);
        }
        //4.Lambda表达式的形式
        System.out.println("-----------------集合的遍历方法4-------------------------------");
//        Consumer<String> consumer = new Consumer<String>() {
//            @Override
//            public void accept(String s) {
//                System.out.println(s);
//            }
//        };
        list.forEach(name -> System.out.println(name));

        list.forEach(System.out::println);


    }

}





















































